package com.jianhua.backend.config;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class WebMvcConfig  implements WebMvcConfigurer {

    //配置跨域请求
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //添加映射
        registry.addMapping("/**")
                //允许所有来源
                .allowedOriginPatterns("*")
                //允许的请求方法
                .allowedMethods("GET","POST","PUT","DELETE","OPTIONS")
                //允许的请求头
                .allowedHeaders("*")
                .maxAge(3600)
                //允许发送Cookie
                .allowCredentials(true);
    }

}
